﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="一分厂费用分配表.aspx.cs" Inherits="syc.ChengBen.一分厂.一分厂费用分配表" %>
<%@ Import  Namespace="System.Data"%>
<%@ Import  Namespace="System.Data.SqlClient"%>
<%@ Import  Namespace="System.Configuration"%>
<html>
<head runat="server">
    <title>一分厂费用归集分配表</title>
</head>
<body>
    <script runat =server>
    protected double 合计;
    protected double 套管金额合计;
    protected double 套管单位费用合计;    
    protected double 油管金额合计;
    protected double 油管单位费用合计;
    protected double 套管累计金额合计;
    protected double 套管累计单位费用合计;
    protected double 油管累计金额合计;
    protected double 油管累计单位费用合计;
    protected double 套管产量;
    protected double 套管累计产量;
    protected double 油管产量;
    protected double 油管累计产量;
    protected int part1Count;
    protected int part2Count;
    protected int part3Count;
    protected int part4Count;
     protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                // Button_Query_Click(null, null);
                this.Year.SelectedValue = DateTime.Today.Year.ToString();
                this.Month.SelectedValue = DateTime.Today.Month.ToString();
            }
        }
    protected void Button_Query_Click(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string part1 = @"<html xmlns:o='urn:schemas-microsoft-com:office:office'
xmlns:x='urn:schemas-microsoft-com:office:excel'
xmlns='http://www.w3.org/TR/REC-html40'>

<head>
<meta http-equiv=Content-Type content='text/html; charset=utf-8'>
<!--[if gte mso 9]><xml>
 <o:DocumentProperties>
  <o:Author>Chinese User</o:Author>
  <o:LastAuthor>Chinese User</o:LastAuthor>
  <o:LastPrinted>2011-05-27T07:18:33Z</o:LastPrinted>
  <o:Created>2011-05-26T03:35:39Z</o:Created>
  <o:LastSaved>2011-05-27T07:19:32Z</o:LastSaved>
  <o:Company>Chinese ORG</o:Company>
  <o:Version>11.9999</o:Version>
 </o:DocumentProperties>
</xml><![endif]-->
<style>
<!--table
	{mso-displayed-decimal-separator:'\.';
	mso-displayed-thousand-separator:'\,';}
@page
	{margin:.16in .49in .13in .68in;
	mso-header-margin:.08in;
	mso-footer-margin:.11in;
	mso-page-orientation:landscape;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-size:14.0pt;
	text-align:center;}
.xl25
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl26
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl27
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl28
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl29
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl30
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl31
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl32
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;}
.xl33
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;}
.xl34
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl35
	{mso-style-parent:style0;
	font-size:11.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl36
	{mso-style-parent:style0;
    text-align:center;	
	font-size:10.0pt;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>6</x:ActiveRow>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8100</x:WindowHeight>
  <x:WindowWidth>12780</x:WindowWidth>
  <x:WindowTopX>360</x:WindowTopX>
  <x:WindowTopY>90</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=1000 style='border-collapse:
 collapse;table-layout:fixed;width:751pt'>
 <col width=150 style='mso-width-source:userset;mso-width-alt:4800;width:113pt'>
 <col width=43 style='mso-width-source:userset;mso-width-alt:1376;width:32pt'>
 <col width=116 style='mso-width-source:userset;mso-width-alt:3712;width:87pt'>
 <col width=141 style='mso-width-source:userset;mso-width-alt:4512;width:106pt'>
 <col width=116 style='mso-width-source:userset;mso-width-alt:3712;width:87pt'>
 <col width=122 style='mso-width-source:userset;mso-width-alt:3904;width:92pt'>
 <col width=163 style='mso-width-source:userset;mso-width-alt:5216;width:122pt'>
 <col width=149 style='mso-width-source:userset;mso-width-alt:4768;width:112pt'>
 <tr height=29 style='mso-height-source:userset;height:21.75pt'>
  <td colspan=8 height=29 class=xl24 width=1000 style='height:21.75pt;
  width:751pt'>一分厂费用归集分配表</td>
 </tr>
 <tr height=17 style='mso-height-source:userset;height:12.75pt'>
  <td height=17 class=xl24 style='height:12.75pt'></td>
  <td colspan=6 class=xl32 >@填报日期</td>
  <td class=xl24></td>
 </tr>
 <tr height=19 style='mso-height-source:userset;height:14.25pt'>
  <td height=19 colspan=6 class=xl24 style='height:14.25pt;mso-ignore:colspan'></td>
  <td colspan=2 class=xl34>单位：元、吨</td>
 </tr>
 <tr height=23 style='mso-height-source:userset;height:17.25pt'>
  <td rowspan=2 height=44 class=xl28 style='border-bottom:.5pt solid black;
  height:33.0pt'>项目</td>
  <td rowspan=2 class=xl28 style='border-bottom:.5pt solid black'>单位</td>
  <td colspan=6 class=xl30 style='border-right:.5pt solid black;border-left:
  none'>套管</td>
 </tr>
 <tr height=21 style='mso-height-source:userset;height:15.75pt'>
  <td height=21 class=xl25 style='height:15.75pt'>数量</td>
  <td class=xl25>金额</td>
  <td class=xl25>单位费用</td>
  <td class=xl25>累计数量</td>
  <td class=xl25>累计金额</td>
  <td class=xl25>累计单位费用</td>
 </tr>";
        string part3 = @" 
<![if supportMisalignedColumns]>
 <tr height=0 style='display:none'>
  <td width=150 style='width:113pt'></td>
  <td width=43 style='width:32pt'></td>
  <td width=116 style='width:87pt'></td>
  <td width=141 style='width:106pt'></td>
  <td width=116 style='width:87pt'></td>
  <td width=122 style='width:92pt'></td>
  <td width=163 style='width:122pt'></td>
  <td width=149 style='width:112pt'></td>
 </tr>
 <![endif]>
</table>"; 
                Response.Charset = "utf-8";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.ContentType = "application/ms-excel";
                Response.AddHeader("content-disposition", "attachment; filename=\"" + Server.UrlEncode("一分厂费用分配表") + ".xls\"");
                Response.Write(part1.Replace("@填报日期",DateTime.Now.ToString("yyyy年MM月dd日")));

                SqlConnection Conn = new SqlConnection();
                Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
                Conn.Open();
                SqlCommand Cmd = new SqlCommand();
                Cmd.Connection = Conn;
                string sql = "";
                DataSet ds = new DataSet();
                string sqlpartCount = @"
               select 财务处.value('count(/root/rnode[1]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[2]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[3]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
               select 财务处.value('count(/root/rnode[4]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                sqlpartCount = sqlpartCount.Replace("@年度", this.Year.Text);
                sqlpartCount = sqlpartCount.Replace("@月份", this.Month.Text);
                SqlDataAdapter sda = new SqlDataAdapter(sqlpartCount, Conn);
                sda.Fill(ds);
                DataTable dt1 = ds.Tables[0];
                DataTable dt2 = ds.Tables[1];
                DataTable dt3 = ds.Tables[2];
                DataTable dt4 = ds.Tables[3];
                try
                {
                    part1Count = int.Parse(dt1.Rows[0][0].ToString());

                    part2Count = int.Parse(dt2.Rows[0][0].ToString());

                    part3Count = int.Parse(dt3.Rows[0][0].ToString());

                    part4Count = int.Parse(dt4.Rows[0][0].ToString());
                }
                catch
                {
                    part1Count = 0;

                    part2Count = 0;

                    part3Count = 0;

                    part4Count = 0;
                }
                //part1
                          string str1 = @"
                            declare @累计金额1 float
                            declare @累计金额2 float 
                            declare @累计金额3 float
                            declare @累计金额4 float

                            declare @累计产量 float   
                            select @累计金额1=sum(财务处.value('(/root/rnode/@cash)[1]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
                            select @累计金额2=sum(财务处.value('(/root/rnode/@cash)[2]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
                            select @累计金额3=sum(财务处.value('(/root/rnode/@cash)[3]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
                            select @累计金额4=sum(财务处.value('(/root/rnode/@cash)[4]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份

                            select @累计产量=isnull(sum(TJ55+TN80),0) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份

                             select '一、'+财务处.value('(/root/rnode/@name)[1]','nvarchar(10)') 
                            ,'' 
                            ,null
                            ,财务处.value('(/root/rnode/@cash)[1]','float')
                            ,round(财务处.value('(/root/rnode/@cash)[1]','float')/(TJ55+TN80),2)
                            ,null
                            ,(select sum(财务处.value('(/root/rnode/@cash)[1]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                            ,round(@累计金额1/@累计产量,2)
                            ,财务处.value('(/root/rnode/@cash)[1]','float') as 金额合计
                            ,(select sum(财务处.value('(/root/rnode/@cash)[1]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
                            ,(TJ55+TN80)
                            ,(select sum(isnull((TJ55+TN80),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份 )   
                            from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                            string sql1 = "";
                                            for (int i = 0; i < part1Count; i++)
                                            {
                                                sql1 += @"               
                            union all             
                                select 财务处.value('(/root/rnode[1]/node/@name)[@i]','nvarchar(10)')
                                ,财务处.value('(/root/rnode[1]/node[@i]/@单位)[1]','nvarchar(10)')              
                                ,财务处.value('(/root/rnode[1]/node/@count)[@i]','float')       
                                ,财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')
                                ,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
                                ,(select sum(isnull(财务处.value('(/root/rnode[1]/node/@count)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                ,(select sum(isnull(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                ,round((select sum(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
                                ,0
                                ,0 
                                ,0    
                                ,0              
                               from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                                sql1 = sql1.Replace("@i", (i + 1).ToString());
                                            }
                                            //part2
                                            string str2 = @"union all  select '二、'+财务处.value('(/root/rnode/@name)[2]','nvarchar(10)')         
                                        ,'' 
                                        ,null
                                        ,财务处.value('(/root/rnode/@cash)[2]','float')
                                        ,round(财务处.value('(/root/rnode/@cash)[2]','float')/(TJ55+TN80),2)
                                        ,null
                                        ,(select sum(财务处.value('(/root/rnode/@cash)[2]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round(@累计金额2/@累计产量,2)
                                        ,财务处.value('(/root/rnode/@cash)[2]','float') as 金额合计
                                        ,(select sum(财务处.value('(/root/rnode/@cash)[2]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
                                        ,0
                                        ,0               
                                       from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                            string sql2 = "";
                                            for (int i = 0; i < part2Count; i++)
                                            {
                                                sql2 += @"union all
                                                  select 财务处.value('(/root/rnode[2]/node/@name)[@i]','nvarchar(10)')
                                        ,财务处.value('(/root/rnode[2]/node[@i]/@单位)[1]','nvarchar(10)')                        
                                        ,财务处.value('(/root/rnode[2]/node/@count)[@i]','float')         
                                        ,财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')
                                        ,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
                                        ,(select sum(isnull(财务处.value('(/root/rnode[2]/node/@count)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,(select sum(isnull(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round((select sum(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
                                        ,0
                                        ,0 
                                        ,0
                                        ,0                          
                                        from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                                sql2 = sql2.Replace("@i", (i + 1).ToString());
                                            }
                                            //part3
                                            string str3 = @"union all  select '三、'+财务处.value('(/root/rnode/@name)[3]','nvarchar(10)')       
                                        ,''
                                        ,null
                                        ,财务处.value('(/root/rnode/@cash)[3]','float')
                                        ,round(财务处.value('(/root/rnode/@cash)[3]','float')/(TJ55+TN80),2)
                                        ,null
                                        ,(select sum(财务处.value('(/root/rnode/@cash)[3]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round(@累计金额3/@累计产量,2)
                                       ,财务处.value('(/root/rnode/@cash)[3]','float') as 金额合计
                                       ,(select sum(财务处.value('(/root/rnode/@cash)[3]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计 
                                       ,0 
                                       ,0                        
                                       from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                            string sql3 = "";
                                            for (int i = 0; i < part3Count; i++)
                                            {
                                                sql3 += @"union all
                                                  select 财务处.value('(/root/rnode[3]/node/@name)[@i]','nvarchar(10)')
                                        ,财务处.value('(/root/rnode[3]/node[@i]/@单位)[1]','nvarchar(10)')                        
                                        ,null         
                                        ,财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')
                                        ,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
                                        ,null
                                        ,(select sum(isnull(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round((select sum(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
                                        ,0
                                        ,0 
                                        ,0 
                                        ,0                                      
                                        from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                                sql3 = sql3.Replace("@i", (i + 1).ToString());
                                            }
                                            //part4
                                            string str4 = @"union all  select '四、'+财务处.value('(/root/rnode/@name)[4]','nvarchar(10)')         
                                        ,''
                                        ,null
                                        ,财务处.value('(/root/rnode/@cash)[4]','float')
                                        ,round(财务处.value('(/root/rnode/@cash)[4]','float')/(TJ55+TN80),2)
                                        ,null
                                        ,(select sum(财务处.value('(/root/rnode/@cash)[4]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round(@累计金额4/@累计产量,2)
                                        ,财务处.value('(/root/rnode/@cash)[4]','float') as 金额合计
                                        ,(select sum(财务处.value('(/root/rnode/@cash)[4]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
                                        ,0
                                        ,0      
                                        from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                            string sql4 = "";
                                            for (int i = 0; i < part4Count; i++)
                                            {
                                                sql4 += @"union all
                                                  select 财务处.value('(/root/rnode[4]/node/@name)[@i]','nvarchar(10)')
                                        ,财务处.value('(/root/rnode[4]/node[@i]/@单位)[1]','nvarchar(10)')  
                                        ,null         
                                        ,财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')
                                        ,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
                                        ,null
                                        ,(select sum(isnull(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
                                        ,round((select sum(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
                                        ,0
                                        ,0 
                                        ,0
                                        ,0               
                                           from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                                                sql4 = sql4.Replace("@i", (i + 1).ToString());
                                            }
                                            sql = str1 + sql1 + str2 + sql2 + str3 + sql3 + str4 + sql4;
                                            sql = sql.Replace("@年度", this.Year.Text);
                                            sql = sql.Replace("@月份", this.Month.Text);
                                            Cmd.CommandText = sql;
                                       

                        SqlDataReader Reader = Cmd.ExecuteReader();

                        while (Reader.Read())
                        {
                            套管金额合计 += double.Parse(Reader[8].ToString());
                            套管累计金额合计 += double.Parse(Reader[9].ToString());
                            套管产量 += double.Parse(Reader[10].ToString());
                            套管累计产量 += double.Parse(Reader[11].ToString());

                            Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>" + Reader.GetString(0) + "</td>");
                            Response.Write("<td class=xl27>" + Reader[1] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[2] + "'>" + Reader[2] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[3] + "'>" + Reader[3] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[4] + "'>" + Reader[4] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[5] + "'>" + Reader[5] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[6] + "'>" + Reader[6] + "</td>");
                            Response.Write("<td class=xl36 x:num='" + Reader[7] + "'>" + Reader[7] + "</td></tr>");
                        }
                        Response.Write(" <tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>合计</td>");
                        Response.Write("<td class=xl27>　</td>");
                        Response.Write("<td class=xl36>　</td>");
                        Response.Write("<td class=xl36>" + 套管金额合计 + "</td>");
                        Response.Write("<td class=xl36>" + double.Parse((套管金额合计 / 套管产量).ToString("0.00")) + "</td>");
                        Response.Write("<td class=xl36>　</td>");
                        Response.Write("<td class=xl36>" + 套管累计金额合计 + "</td>");
                        Response.Write("<td class=xl36>" + double.Parse((套管累计金额合计 / 套管累计产量).ToString("0.00")) + "</td></br>");
                        Response.Write("<tr height=19 style='height:14.25pt'><td height=19 class=xl26 style='height:14.25pt'>产量</td>");
                        Response.Write("<td class=xl27>　</td>");
                        Response.Write("<td class=xl36>" + 套管产量 + "</td>");
                        Response.Write("<td class=xl36>　</td>");
                        Response.Write("<td class=xl36>　</td>");
                        Response.Write("<td class=xl36>" + 套管累计产量 + "</td>");
                        Response.Write("<td class=xl36>　</td>");
                        Response.Write("<td class=xl36>　</td></tr>");

                  Response.Write("<tr height=26 style='mso-height-source:userset;height:19.5pt'><td height=26 style='height:19.5pt'></td><td colspan=2 class=xl35>单位负责人:</font></td>");
                  Response.Write("<td colspan=3 style='mso-ignore:colspan'></td>");
                  Response.Write("<td colspan=2 class=xl35>制表：刘弘波</td></tr>");

                  Conn.Close();
                  Response.Write(part3);
                  Response.End();
          
    }
 </script>
    <script type="text/javascript" language="javascript" src="/common.js"></script>
   <form id="form1" runat="server">  
      <div id="wintop" class="wintop"><span lang="zh-cn">一分厂费用归集分配表</span></div>
        <asp:Panel ID="Panel1" runat="server" CssClass="panel" Height="36px" >   
              年份：<asp:DropDownList ID="Year" runat="server">         
            <asp:ListItem>2010</asp:ListItem>
            <asp:ListItem>2011</asp:ListItem>
            <asp:ListItem>2012</asp:ListItem>
            <asp:ListItem>2013</asp:ListItem>
            <asp:ListItem>2014</asp:ListItem>
            <asp:ListItem>2015</asp:ListItem>   
            <asp:ListItem>2016</asp:ListItem>
            <asp:ListItem>2017</asp:ListItem>
            <asp:ListItem>2018</asp:ListItem>
            <asp:ListItem>2019</asp:ListItem>
            <asp:ListItem>2020</asp:ListItem>                
            </asp:DropDownList>
            <span lang="zh-cn">&nbsp;月份：</span><asp:DropDownList ID="Month" runat="server">
                <asp:ListItem>1</asp:ListItem>
                <asp:ListItem>2</asp:ListItem>
                <asp:ListItem>3</asp:ListItem>
                <asp:ListItem>4</asp:ListItem>
                <asp:ListItem>5</asp:ListItem>
                <asp:ListItem>6</asp:ListItem>
                <asp:ListItem>7</asp:ListItem>
                <asp:ListItem>8</asp:ListItem>
                <asp:ListItem>9</asp:ListItem>
                <asp:ListItem>10</asp:ListItem>
                <asp:ListItem>11</asp:ListItem>
                <asp:ListItem>12</asp:ListItem>
            </asp:DropDownList>
      <span lang="zh-cn">&nbsp;&nbsp;</span><asp:Button ID="Button_Query"
            runat="server" Text="查看报表" CssClass="button" UseSubmitBehavior="true" onclick="Button_Query_Click" 
             />            
            &nbsp;<asp:Button ID="Button1" runat="server" class="button" onclick="Button1_Click" 
                Text="导 出" />
      </asp:Panel>
        <asp:Panel ID="Panel2" runat="server" CssClass="panel2">
        <asp:Label ID="Message" runat="server" Text="·准备就绪" CssClass="prompt" Visible="True"></asp:Label>
        </asp:Panel> 
     <div align="center">
    <style>
<!--table
	{mso-displayed-decimal-separator:"\.";
	mso-displayed-thousand-separator:"\,";}
@page
	{margin:.13in .49in .13in .68in;
	mso-header-margin:.08in;
	mso-footer-margin:.11in;
	mso-page-orientation:landscape;}
.font0
	{color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;}
.font5
	{color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;}
tr
	{mso-height-source:auto;
	mso-ruby-visibility:none;}
col
	{mso-width-source:auto;
	mso-ruby-visibility:none;}
br
	{mso-data-placement:same-cell;}
.style0
	{mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	white-space:nowrap;
	mso-rotate:0;
	mso-background-source:auto;
	mso-pattern:auto;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	border:none;
	mso-protection:locked visible;
	mso-style-name:常规;
	mso-style-id:0;}
td
	{mso-style-parent:style0;
	padding-top:1px;
	padding-right:1px;
	padding-left:1px;
	mso-ignore:padding;
	color:windowtext;
	font-size:12.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-number-format:General;
	text-align:general;
	vertical-align:middle;
	border:none;
	mso-background-source:auto;
	mso-pattern:auto;
	mso-protection:locked visible;
	white-space:nowrap;
	mso-rotate:0;}
.xl24
	{mso-style-parent:style0;
	font-size:10.0pt;}
.xl25
	{mso-style-parent:style0;
	font-size:9.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl26
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:right;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl27
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl28
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:none;
	border-left:.5pt solid windowtext;}
.xl29
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid black;
	border-left:.5pt solid windowtext;}
.xl30
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl31
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl32
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid black;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl33
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:left;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl34
	{mso-style-parent:style0;
	text-align:center;
	vertical-align:bottom;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;
	white-space:normal;}
.xl35
	{mso-style-parent:style0;
	text-align:center;
	vertical-align:bottom;
	border-top:none;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl36
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:none;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl37
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:right;
	vertical-align:bottom;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl38
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	vertical-align:bottom;
	border:.5pt solid windowtext;}
.xl39
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:.5pt solid windowtext;
	border-bottom:.5pt solid windowtext;
	border-left:none;}
.xl40
	{mso-style-parent:style0;
	font-size:10.0pt;
	mso-number-format:"0\.00_\)\;\[Red\]\\\(0\.00\\\)";
	text-align:center;
	border:.5pt solid windowtext;}
.xl41
	{mso-style-parent:style0;
	font-size:10.0pt;
	mso-number-format:"0\.00_ ";
	text-align:center;
	border:.5pt solid windowtext;}
.xl42
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	border:.5pt solid windowtext;}
.xl43
	{mso-style-parent:style0;
	font-size:10.0pt;
	text-align:center;
	vertical-align:bottom;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:.5pt solid windowtext;
	border-left:.5pt solid windowtext;}
.xl44
	{mso-style-parent:style0;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl45
	{mso-style-parent:style0;
	text-align:center;
	border-top:.5pt solid windowtext;
	border-right:none;
	border-bottom:none;
	border-left:none;}
.xl46
	{mso-style-parent:style0;
	font-size:14.0pt;
	text-align:center;}
ruby
	{ruby-align:left;}
rt
	{color:windowtext;
	font-size:9.0pt;
	font-weight:400;
	font-style:normal;
	text-decoration:none;
	font-family:宋体;
	mso-generic-font-family:auto;
	mso-font-charset:134;
	mso-char-type:none;
	display:none;}
-->
</style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:Print>
      <x:ValidPrinterInfo/>
      <x:PaperSizeIndex>9</x:PaperSizeIndex>
      <x:HorizontalResolution>600</x:HorizontalResolution>
      <x:VerticalResolution>600</x:VerticalResolution>
     </x:Print>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>10</x:ActiveRow>
       <x:ActiveCol>5</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>285</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8100</x:WindowHeight>
  <x:WindowWidth>12780</x:WindowWidth>
  <x:WindowTopX>360</x:WindowTopX>
  <x:WindowTopY>90</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
 <x:SupBook>
  <x:Path>\离线\一分厂\一分厂成本表1月.xls</x:Path>
  <x:SheetName>各种材料领用表</x:SheetName>
  <x:SheetName>收发存</x:SheetName>
  <x:SheetName>产品计算单2</x:SheetName>
  <x:Xct>
   <x:Count>0</x:Count>
   <x:SheetIndex>0</x:SheetIndex>
  </x:Xct>
  <x:Xct>
   <x:Count>0</x:Count>
   <x:SheetIndex>1</x:SheetIndex>
  </x:Xct>
  <x:Xct>
   <x:Count>0</x:Count>
   <x:SheetIndex>2</x:SheetIndex>
  </x:Xct>
 </x:SupBook>
</xml><![endif]-->
</head>

<body link=blue vlink=purple>

<table x:str border=0 cellpadding=0 cellspacing=0 width=1000 style='border-collapse:
 collapse;table-layout:fixed;width:751pt'>
 <col width=150 style='mso-width-source:userset;mso-width-alt:4800;width:113pt'>
 <col width=43 style='mso-width-source:userset;mso-width-alt:1376;width:32pt'>
 <col width=116 style='mso-width-source:userset;mso-width-alt:3712;width:87pt'>
 <col width=141 style='mso-width-source:userset;mso-width-alt:4512;width:106pt'>
 <col width=116 style='mso-width-source:userset;mso-width-alt:3712;width:87pt'>
 <col width=122 style='mso-width-source:userset;mso-width-alt:3904;width:92pt'>
 <col width=163 style='mso-width-source:userset;mso-width-alt:5216;width:122pt'>
 <col width=149 style='mso-width-source:userset;mso-width-alt:4768;width:112pt'>
 <tr height=24 style='mso-height-source:userset;height:18.0pt'>
  <td colspan=8 height=24 class=xl46 width=1000 style='height:18.0pt;
  width:751pt'>一分厂费用归集分配表</td>
 </tr>
 <tr height=35 style='mso-height-source:userset;height:26.25pt'>
  <td colspan=8 height=35 class=xl34 width=960 style='height:26.25pt;
  width:751pt'><%=DateTime.Today.ToString("yyyy年MM月dd日") %><br>
  <span  style='mso-spacerun:yes'>                                                                  
  </span>单位：元 吨                                                                                                                                                                                                                 </span></font></td>
 </tr>
 <tr height=23 style='mso-height-source:userset;height:17.25pt'>
  <td rowspan=2 height=44 class=xl28 style='border-bottom:.5pt solid black;
  height:33.0pt;border-top:none'>项目</td>
  <td rowspan=2 class=xl28 style='border-bottom:.5pt solid black;border-top:
  none'>单位</td>
  <td colspan=6 class=xl31 style='border-right:.5pt solid black;border-left:
  none'>套管</td>
 </tr>
 <tr height=21 style='mso-height-source:userset;height:15.75pt'>
  <td height=21 class=xl25 style='height:15.75pt'>数量</td>
  <td class=xl25>金额</td>
  <td class=xl25>单位费用</td>
  <td class=xl25>累计数量</td>
  <td class=xl25>累计金额</td>
  <td class=xl25>累计单位费用</td>
 </tr>
  <%         
        SqlConnection Conn = new SqlConnection();
        Conn.ConnectionString = ConfigurationManager.ConnectionStrings["SCMConnectionString1"].ConnectionString;
        Conn.Open();
        SqlCommand Cmd = new SqlCommand();
        Cmd.Connection = Conn;
        string sql="";
       DataSet ds = new DataSet();
       string sqlpartCount = @"
       select 财务处.value('count(/root/rnode[1]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[2]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[3]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份
       select 财务处.value('count(/root/rnode[4]/*)','int') from 分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
       sqlpartCount = sqlpartCount.Replace("@年度", this.Year.Text);
       sqlpartCount = sqlpartCount.Replace("@月份", this.Month.Text);
       SqlDataAdapter sda = new SqlDataAdapter(sqlpartCount, Conn);
       sda.Fill(ds);
       DataTable dt1 = ds.Tables[0];
       DataTable dt2 = ds.Tables[1];
       DataTable dt3 = ds.Tables[2];
       DataTable dt4 = ds.Tables[3];
       try
       {
           part1Count = int.Parse(dt1.Rows[0][0].ToString());

           part2Count = int.Parse(dt2.Rows[0][0].ToString());

           part3Count = int.Parse(dt3.Rows[0][0].ToString());

           part4Count = int.Parse(dt4.Rows[0][0].ToString());
       }
       catch
       {
           part1Count = 0;

           part2Count = 0;

           part3Count = 0;

           part4Count = 0;
       }
        //part1
        string str1 = @"
declare @累计金额1 float
declare @累计金额2 float 
declare @累计金额3 float
declare @累计金额4 float

declare @累计产量 float   
select @累计金额1=sum(财务处.value('(/root/rnode/@cash)[1]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
select @累计金额2=sum(财务处.value('(/root/rnode/@cash)[2]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
select @累计金额3=sum(财务处.value('(/root/rnode/@cash)[3]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份
select @累计金额4=sum(财务处.value('(/root/rnode/@cash)[4]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份

select @累计产量=isnull(sum(TJ55+TN80),0) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份

 select '一、'+财务处.value('(/root/rnode/@name)[1]','nvarchar(10)') 
,'' 
,null
,财务处.value('(/root/rnode/@cash)[1]','float')
,round(财务处.value('(/root/rnode/@cash)[1]','float')/(TJ55+TN80),2)
,null
,(select sum(财务处.value('(/root/rnode/@cash)[1]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
,round(@累计金额1/@累计产量,2)
,财务处.value('(/root/rnode/@cash)[1]','float') as 金额合计
,(select sum(财务处.value('(/root/rnode/@cash)[1]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
,(TJ55+TN80)
,(select sum(isnull((TJ55+TN80),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份 )   
from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
        string sql1 = "";
            for (int i = 0; i < part1Count; i++)
            {
                sql1 += @"               
union all             
    select 财务处.value('(/root/rnode[1]/node/@name)[@i]','nvarchar(10)')
    ,财务处.value('(/root/rnode[1]/node[@i]/@单位)[1]','nvarchar(10)')              
    ,财务处.value('(/root/rnode[1]/node/@count)[@i]','float')       
    ,财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')
    ,round(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
    ,(select sum(isnull(财务处.value('(/root/rnode[1]/node/@count)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
    ,(select sum(isnull(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
    ,round((select sum(财务处.value('(/root/rnode[1]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
    ,0
    ,0 
    ,0    
    ,0              
   from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";          
            sql1 = sql1.Replace("@i", (i + 1).ToString());
        }
          //part2
           string str2 = @"union all  select '二、'+财务处.value('(/root/rnode/@name)[2]','nvarchar(10)')         
            ,'' 
            ,null
            ,财务处.value('(/root/rnode/@cash)[2]','float')
            ,round(财务处.value('(/root/rnode/@cash)[2]','float')/(TJ55+TN80),2)
            ,null
            ,(select sum(财务处.value('(/root/rnode/@cash)[2]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round(@累计金额2/@累计产量,2)
            ,财务处.value('(/root/rnode/@cash)[2]','float') as 金额合计
            ,(select sum(财务处.value('(/root/rnode/@cash)[2]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
            ,0
            ,0               
           from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
        string sql2 = "";
               for (int i = 0; i < part2Count; i++)
                {
                    sql2 += @"union all
                      select 财务处.value('(/root/rnode[2]/node/@name)[@i]','nvarchar(10)')
            ,财务处.value('(/root/rnode[2]/node[@i]/@单位)[1]','nvarchar(10)')                        
            ,财务处.value('(/root/rnode[2]/node/@count)[@i]','float')         
            ,财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')
            ,round(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
            ,(select sum(isnull(财务处.value('(/root/rnode[2]/node/@count)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,(select sum(isnull(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round((select sum(财务处.value('(/root/rnode[2]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
            ,0
            ,0 
            ,0
            ,0                          
            from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                    sql2 = sql2.Replace("@i", (i + 1).ToString());
                }
          //part3
          string str3 = @"union all  select '三、'+财务处.value('(/root/rnode/@name)[3]','nvarchar(10)')       
            ,''
            ,null
            ,财务处.value('(/root/rnode/@cash)[3]','float')
            ,round(财务处.value('(/root/rnode/@cash)[3]','float')/(TJ55+TN80),2)
            ,null
            ,(select sum(财务处.value('(/root/rnode/@cash)[3]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round(@累计金额3/@累计产量,2)
           ,财务处.value('(/root/rnode/@cash)[3]','float') as 金额合计
           ,(select sum(财务处.value('(/root/rnode/@cash)[3]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计 
           ,0 
           ,0                        
           from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
          string sql3 = "";
          for (int i = 0; i < part3Count; i++)
          {
              sql3 += @"union all
                      select 财务处.value('(/root/rnode[3]/node/@name)[@i]','nvarchar(10)')
            ,财务处.value('(/root/rnode[3]/node[@i]/@单位)[1]','nvarchar(10)')                        
            ,null         
            ,财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')
            ,round(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
            ,null
            ,(select sum(isnull(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round((select sum(财务处.value('(/root/rnode[3]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
            ,0
            ,0 
            ,0 
            ,0                                      
            from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
              sql3 = sql3.Replace("@i", (i + 1).ToString());
          }
           //part4
            string str4 = @"union all  select '四、'+财务处.value('(/root/rnode/@name)[4]','nvarchar(10)')         
            ,''
            ,null
            ,财务处.value('(/root/rnode/@cash)[4]','float')
            ,round(财务处.value('(/root/rnode/@cash)[4]','float')/(TJ55+TN80),2)
            ,null
            ,(select sum(财务处.value('(/root/rnode/@cash)[4]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round(@累计金额4/@累计产量,2)
            ,财务处.value('(/root/rnode/@cash)[4]','float') as 金额合计
            ,(select sum(财务处.value('(/root/rnode/@cash)[4]','float')) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) as 累计金额合计
            ,0
            ,0      
            from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
            string sql4 = "";
            for (int i = 0; i < part4Count; i++)
            {
                sql4 += @"union all
                      select 财务处.value('(/root/rnode[4]/node/@name)[@i]','nvarchar(10)')
            ,财务处.value('(/root/rnode[4]/node[@i]/@单位)[1]','nvarchar(10)')  
            ,null         
            ,财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')
            ,round(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float')/(TJ55+TN80),2)    
            ,null
            ,(select sum(isnull(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float'),0)) from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份) 
            ,round((select sum(财务处.value('(/root/rnode[4]/node/@cash)[@i]','float'))  from 分厂费用归集表 where year=@年度 and  分厂=1 and month between 1 and @月份)/@累计产量,2) 
            ,0
            ,0 
            ,0
            ,0               
               from  分厂费用归集表 where 分厂=1 and year=@年度 and month=@月份";
                sql4 = sql4.Replace("@i", (i + 1).ToString());
            }             
            sql = str1 + sql1+ str2 + sql2 + str3 + sql3 + str4 + sql4;
            sql = sql.Replace("@年度", this.Year.Text);
            sql = sql.Replace("@月份", this.Month.Text);
            Cmd.CommandText = sql;
           
            SqlDataReader Reader = Cmd.ExecuteReader();
            try
            {               
                while (Reader.Read())
                    {                       
                        套管金额合计 += double.Parse(Reader[8].ToString());                      
                        套管累计金额合计 += double.Parse(Reader[9].ToString());                    
                        套管产量 += double.Parse(Reader[10].ToString());
                        套管累计产量 += double.Parse(Reader[11].ToString());                       
                    %>
                <tr height=19 style='height:14.25pt'>
                  <td height=19 class=xl36 style='height:14.25pt'><%=Reader[0]%></td>
                  <td class=xl36><%=Reader[1]%></td>
                  <td class=xl26><%=Reader[2]%></td>
                  <td class=xl26><%=Reader[3]%></td>
                  <td class=xl27><%=Reader[4]%></td>
                  <td class=xl26><%=Reader[5]%></td>
                  <td class=xl26><%=Reader[6]%></td>
                  <td class=xl27><%=Reader[7]%></td>
                 </tr>      
              <%  
                 }
                 
              %>                         

                <tr height=19 style='height:14.25pt'>
                  <td height=19 class=xl36 style='height:14.25pt'>合计</td>
                  <td class=xl33>　</td>
                  <td class=xl26>　</td>
                  <td class=xl26><%=套管金额合计%></td>
                  <td class=xl27><%=double.Parse((套管金额合计 / 套管产量).ToString("0.00"))%></td>
                  <td class=xl26>　</td>
                  <td class=xl26><%=套管累计金额合计%></td>
                  <td class=xl27><%=double.Parse((套管累计金额合计 / 套管累计产量).ToString("0.00"))%></td>
                 </tr> 
                 <tr height=19 style='height:14.25pt'>
                  <td height=19 class=xl36 style='height:14.25pt'>产量</td>
                  <td class=xl33>　</td>
                  <td class=xl26><%=套管产量%></td>
                  <td class=xl26>　</td>
                  <td class=xl27>　</td>
                  <td class=xl26><%=套管累计产量%></td>
                  <td class=xl26>　</td>
                  <td class=xl27>　</td>
                 </tr> 
                 <tr height=26 style='mso-height-source:userset;height:19.5pt'>
                  <td height=26 style='height:19.5pt'></td>
                  <td class=xl44 colspan=2 style='mso-ignore:colspan'><span
                  style='mso-spacerun:yes'> </span><font class="font0"><span
                  style='mso-spacerun:yes'>    </span></font><font class="font5">单位负责人：</font></td>
                  <td class=xl44 style='border-top:none'>　</td>
                  <td class=xl44 style='border-top:none'>　</td>
                  <td class=xl44 style='border-top:none'>　</td>
                  <td colspan=2 class=xl45>制表：刘弘波</td>
                 </tr>
   <%           Reader.Close();
                Cmd.Clone();
                Conn.Close();
            }
            catch (Exception ex)
            {
                this.Message.Text="请输入套管或油管产量!";
                return;
            }
     %>                          
    </div>
    </form>
</body>
</html>
